package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.ProprietaryDriverEntity;
import com.swgk.core.util.UserOperating;

import java.util.List;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/10/12
 */
public class ProprietaryDriverListAdapter extends BaseQuickAdapter<ProprietaryDriverEntity, BaseViewHolder> {
    private Context mContext;

    public ProprietaryDriverListAdapter(Context context, @Nullable List<ProprietaryDriverEntity> data) {
        super(R.layout.app_pro_driver_item_layout, data);
        this.mContext = context;
    }

    @Override
    protected void convert(@Nullable BaseViewHolder helper, ProprietaryDriverEntity item) {
        helper.setText(R.id.driver_name, !TextUtils.isEmpty(item.getName()) ? item.getName() : "")
                .setText(R.id.belongs_team_name, !TextUtils.isEmpty(item.getMotorcadeName()) ? item.getMotorcadeName() : "/");

        boolean isTeam = UserOperating.getInstance().isTeam();
        //团队的自营司机不可以编辑车队
        helper.setVisible(R.id.edit_btn, isTeam ? false : true);
        helper.setVisible(R.id.belongs_team_hint, isTeam ? false : true);
        helper.setVisible(R.id.belongs_team_name, isTeam ? false : true);

        if (item.isHasMotorcade()){
            helper.setText(R.id.edit_btn,"编辑所属车队");
        }else {
            helper.setText(R.id.edit_btn,"添加车队");
        }

        helper.setVisible(R.id.bottom_bar, true);
        helper.setVisible(R.id.line, true);
        if (item.getLinkState() != null) {
            switch (item.getLinkState()) {
                case 1:
                    helper.setText(R.id.statues, "邀请中")
                            .setTextColor(R.id.statues, mContext.getResources().getColor(R.color.color_5792FD))
                            .setVisible(R.id.unbind_btn, false);
                    if (isTeam) {
                        helper.setVisible(R.id.bottom_bar, false);
                        helper.setVisible(R.id.line, false);
                    }
                    break;
                case 3:
                    helper.setText(R.id.statues, "已同意")
                            .setTextColor(R.id.statues, mContext.getResources().getColor(R.color.color_06C764))
                            .setText(R.id.unbind_btn, "解除关系")
                            .setVisible(R.id.unbind_btn, true);
                    break;
                case 2:
                    helper.setText(R.id.statues, "已拒绝")
                            .setTextColor(R.id.statues, mContext.getResources().getColor(R.color.color_FF4B10))
                            .setText(R.id.unbind_btn, "删除")
                            .setVisible(R.id.unbind_btn, true);
                    break;
                case 4:
                    helper.setText(R.id.statues, "已解除")
                            .setTextColor(R.id.statues, mContext.getResources().getColor(R.color.color_FF4B10))
                            .setText(R.id.unbind_btn, "删除")
                            .setVisible(R.id.unbind_btn, true);
                    break;
            }
        }

        if (item.getDriverState() != null)
            switch (item.getDriverState()) {
                case 0:
                    helper.setText(R.id.certification_state, "审核中")
                            .setTextColor(R.id.certification_state, mContext.getResources().getColor(R.color.color_5792FD));
                    break;
                case 1:
                    helper.setText(R.id.certification_state, "审核通过")
                            .setTextColor(R.id.certification_state, mContext.getResources().getColor(R.color.color_06C764));
                    break;
                case 2:
                    helper.setText(R.id.certification_state, "审核不通过")
                            .setTextColor(R.id.certification_state, mContext.getResources().getColor(R.color.color_969696));
                    break;
            }

        helper.addOnClickListener(R.id.unbind_btn)
                .addOnClickListener(R.id.edit_btn)
                .addOnClickListener(R.id.item_layout);
    }
}
